package com.xch.sboot.web.api.common;

import com.xch.sboot.common.response.Result;
import com.xch.sboot.config.login.NoNeedLogin;
import com.xch.sboot.service.common.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author xch
 * 2022/12/14 15:47
 */

@RestController
@RequestMapping("/common")
@Api(tags = "公共接口")
public class CommonController {

    @Autowired
    private CommonService commonService;

    @GetMapping("/publickey")
    @NoNeedLogin
    @ApiOperation("获取公钥，request_id 为空则使用固定公钥私钥; 不为空则动态生成公私钥, 且后续加密传输(创建用户，登录)的接口都需要增加请求头Request-Id:request_id以供后端获取秘钥对解密使用,动态公私钥对只使用一次")
    public Result<String> getPublicKey(@RequestParam(name = "request_id", required = false) String requestId) {
        String key = commonService.getPublicKey(requestId);
        return Result.newR(key);
    }
}
